package com.poseidon.prototype;


import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
//INVOCA XMLhandler per gestire i vari tag del file XML

public class XMLparse {
	private Physics physics;

	public XMLparse(String sourceFile){


 		try {

             /* Create a URL we want to load some xml-data from. */

             /* Get a SAXParser from the SAXPArserFactory. */
             SAXParserFactory spf = SAXParserFactory.newInstance();
             SAXParser sp = spf.newSAXParser();
             /* Get the XMLReader of the SAXParser we created. */
             XMLReader xr = sp.getXMLReader();
             /* Create a new ContentHandler and apply it to the XML-Reader*/
             XMLhandler myHandler = new XMLhandler();
             xr.setContentHandler(myHandler);
          	 xr.parse(new InputSource(sourceFile));

             /* Our ExampleHandler now provides the parsed data to us. */
             physics = myHandler.getParsedData();


     //		startSomethings();

        } catch (Exception e) {
             /* Display any Error to the GUI. */
    		System.out.println(e.toString());

        }

        //stoppa il questo servizio
	}

	public void startSomethings() {

		//Return the physics
    //    System.out.println(physics.toString());


	//	if (physics.isGravity());
	//		System.out.println(physics.getGravityValue());
	//	if (physics.isrobotMass());
	//		System.out.println(physics.getMassValue());
	//	if (physics.isRobotMaxSpeed());
	//		System.out.println(physics.getRobotMaxSpeed());
	//	if (physics.isFriction());
	//		System.out.println(physics.getFriction());
	}

	public Physics getPhysics() {
		//calcolate the other para
		this.physics.calcolateRobotVolume();
		this.physics.calcolateRobotDensity();
		this.physics.calcolateLiftPushUp();
		this.physics.calcolateGravityPushDown();
		this.physics.calcolateImpulse(1);
		this.physics.calcolateFriction(1);
		return physics;
	}

}


